package com.qf.controller;

import com.qf.business.entity.Student;
import com.qf.business.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;

/**
 * description:
 * author: Ken
 * 公众号：Java架构栈
 */
@Controller
@RequestMapping("/stu")
@SessionAttributes("login_stu")
public class StuController {

    @Autowired
    private StudentService studentService;

    @RequestMapping("/login")
    public String login(String username, String password, Model model){

        Student stu = studentService.login(username, password);
        if (stu != null) {
            model.addAttribute("login_stu", stu);
            //登录成功
            return "index";
        }
        //跳回登录页
        return "redirect:/?status=1";
    }
}
